package base;

import javax.xml.transform.Source;
import java.util.Scanner;

/*前缀和算法：
    一维前缀和：
        初始化公式：`s[i] = s[i - 1] + a[i]`
        求区间和公式：`ans = s[r] - s[l - 1]`
    二维前缀和：
        初始化公式：`s[i][j] = s[i-1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j]`
        求区间和公式：`ans = s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1]`*/
public class PrefixSum {

    //例题：https://www.nowcoder.com/practice/acead2f4c28c401889915da98ecdc6bf?tpId=230&tqId=2021480&ru=/exam/oj&qru=/ta/dynamic-programming/question-ranking&sourceUrl=%2Fexam%2Foj%3Fpage%3D1%26tab%3D%25E7%25AE%2597%25E6%25B3%2595%25E7%25AF%2587%26topicId%3D196
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        int[] nums = new int[n+1];
        long[] sum = new long[n+1];
        sum[0] = 0;
        for (int i = 1; i <= n; i++) {
            nums[i] = sc.nextInt();
            sum[i] = sum[i-1] + nums[i];
        }
        for (int i = 0; i < q; i++) {
            int left = sc.nextInt();
            int right = sc.nextInt();
            System.out.println(sum[right] - sum[left-1]);
        }
    }
}
